<?php

require_once 'Global.php';

class ConnectionManager {
    
       private $link;
    
       public function __construct(){
           $this->link = mysql_connect(MYSQL_SERVER, MYSQL_LOGIN, MYSQL_PASSWORD);
           @mysql_select_db(MYSQL_DB, $this->link) or die("Unable to select database");
       }
       
       public function SelectSignleRow($table,$where_clause){
           
           $query = "SELECT * FROM ".$table." WHERE ".$where_clause;
           $result=mysql_query($query);
           
           $row = mysql_fetch_array($result);
           
           return $row;
       }
       public function SelectMultipleRows($table,$where_clause){
            $query = "SELECT * FROM ".$table." WHERE ".$where_clause;
            $result=mysql_query($query);
            for($row = mysql_fetch_array($result), $i=0; $row; $row = mysql_fetch_array($result), $i++){
                  $retVal[$i] = $row;  
            }
            if(count($retVal) <= 0) return false;
            else return $retVal;
       }
       public function InsertRow($table,$fields, $values){
           $alanlar = "";
           for($i = 0; $i < count($fields); $i++) $alanlar .= $fields[i].",";
           $alanlar = substr($alanlar, 0, strlen($alanlar) - 1);
           
           $değerler = "";
           for($i = 0; $i < count($values); $i++) $değerler .= "'".$values[i]."',";
           $değerler = substr($değerler, 0, strlen($değerler) - 1);
           
           
           $query = "INSERT INTO ".$table."(".$alanlar.") VALUES(".$değerler.")";
           mysql_query($query);
           
           
       }
       public function DeleteRow($table,$where_clause){
           $query = "DELETE FROM ".$table." ".$where_clause;
       }
       public function UpdateRow($table,$where_clause,$fields, $values){
           $setter = "";
           for($i = 0; $i < count($fields); $i++){
               $setter .= " ".$fields[$i]." = '".$values[$i]."',";
           }        
           $setter = substr($setter, 0, strlen($setter) - 1);
           
           $query = "UPDATE ".$table." SET ".$setter." WHERE ".$where_clause; 
           mysql_query($query);
       }
       
        public function __destruct() {
          mysql_close( $this->link );
       }
       
       
}
    
    
    

?>
